SNES Killer instinct US 1.1 by gizaha
ips patch v1.0 (02/2018)
-------------------------------------
Ram addresses:
$7ff100 Store track id here,because the original track id will always be set to 04 (glacius) because its muted.
$7ff103 msu playing flag (1=playing)

Zero tempo on the above spc tracks in order to mute them:
The instinct  $41166=00 
Glacius       $43001=00
Char. select  $465ff=00
Bass loop     $46590=00
Humiliation   $41cdc=00
End Credits   $415d0=00
-------------------------------------



$81EFED:
4C f9 F4      ;jump 81F4F9

$81F4F9:       ;if track is 0-0b, set track to glacius theme, otherwise don't touch it.
AD Dc 17      ;lda 17dc     original from 81EFED
8f 00 f1 7f   ;sta 7ff100   save the track id in here
c9 0c 00      ;cmp 000c
10 06         ;bpl 06       if plus skip the next 2 lines (music is not belong to stage)
a9 04 00      ;lda 0004     (0004=glacius music)
8d dc 17      ;sta 17dc     set new track id
4c f0 ef      ;jmp eff0     return to original code





$81F461:
4c 0e f5      ;jump 81F50E

$81F50E:
c9 fe 00      ;cmp 00fe     (fe command starts music)
f0 69         ;beq PLAYMSU

c9 ff 00      ;cmp 00ff     (ff command stops music)
d0 0a         ;bne          goto next case if it's not 00ff
a9 00 00      ;lda 0000
8f 03 f1 7f   ;sta 7ff103   set msu playing flag to zero
a9 ff 00      ;lda 00ff     set it 00ff again

c9 fb 01      ;cmp 01fb     (01fb="danger themes")
d0 17         ;bne          goto next case if it's not 01fb
a9 00 00      ;lda 0000
8f 03 f1 7f   ;sta 7ff103   set msu playing flag to zero
af 00 f1 7f   ;lda 7f100    load track id
69 12 00      ;and 12       adds 18 to track id to become danger music.
8f 00 f1 7f   ;sta 7ff100
a9 fb 00      ;lda 00fb     set it 00fb to keep silent (danger spc themes are not muted)
80 3e         ;bra 3e       branch always to PLAYMSU

c9 fb 02      ;cmp 02fb     (02fb=end stage theme)
d0 1f         ;bne          goto next case if it's not 02fb
a9 00 00      ;lda 0000
8f 03 f1 7f   ;sta 7ff103   set msu playing flag to zero
af 00 f1 7f   ;lda 7ff100   load track id
c9 0c 00      ;cmp 000c
10 03         ;bpl 03       skip the next line if it's already on danger theme
69 14 00      ;and 20       set it from normal to danger music (needed for "time out" case)
69 0b 00      ;and 11       set it from danger to end stage
8f 00 f1 7f   ;sta 7ff100   sta track id
a9 fb 00      ;a9 00fb      set it 00fb to keep it silent (end stage themes are not muted)
80 1a         ;bra 1a       branch always to PLAYMSU

c9 fb 03      ;cmp 03fb     (03fb=fatality sound)
d0 13         ;bne 13       goto next case if it's not 03fb
a9 00 00      ;lda 0000
8f 03 f1 7f   ;sta 7ff103   set msu playing flag to zero
a9 2c 00      ;lda 002c     track=2c+1=2d = ki-45.pcm (fatality sound)
8f 00 f1 7f   ;sta 7ff100   set track id to 45
a9 fb 00      ;lda 00fb     set it 00fb to keep it silent, otherwise spc will try play sfx 002d.
80 02         ;bra 02       branch always to PLAYMSU

80 3d         ;bra 44       ;branch always to end (but after pla)
                            ;it wasnt 00ff, 00fe, 01fe etc. It was SFX, so does not
                            ;concern msu. We give the sound code untouched to 2141.






PLAYMSU:
48            ;pha
08            ;PHP processor status on stack
E2 20         ;SEP #$20; , set M to 8bit
af 03 f1 7f   ;lda 7ff103   load msu playing flag
c9 01         ;cmp 01
f0 2f         ;beq 2f       branch to plp before end end because msu is already playing music. >>>>
a9 01         ;lda 01
8f 03 f1 7f   ;sta 7ff103   set msu playing flag to 01
af 00 f1 7f   ;lda 7ff100   load track id
1a            ;inc a        because jago track is 0 and jago pcm is ki-01.pcm
9C 06 20      ;stz $2006 ; prevent buzz on sd2snes
8d 04 20      ;sta 2004
9c 05 20      ;stz 2005
2c 00 20      ;bit 2020; 
70 fb         ;bvs          ;msu busy, better than the code before with and #$40
a9 30         ;lda 30       volume=30 in 8 bit
8d 06 20      ;sta 2006    
af 00 f1 7f   ;lda 7ff100   load track id (it's already +1)
c9 1f         ;cmp 1f       track id>1f, sets loop to 03 (no loop), 8 bit
10 04         ;bpl          if plus skip the next 2 lines, only 4 bytes
a9 03         ;lda 03     loop; 8 bit
80 02         ;bra 02       skip the next line; 2 bytes
a9 01         ;lda 01     no loop, 2 bytes
8d 07 20      ;sta 2007     set loop state
28            ; PLP ; restore processor status



END:
68            ;pla
8d 41 21      ;sta 2141     original from 81F461
4c 64 f4      ;jmp          return  to the original code





